package com.rightsidetech.http.controller.userApp.login;

import com.rightsidetech.commom.base.ResponseData;
import com.rightsidetech.http.aspect.Log;
import com.rightsidetech.http.aspect.Token;
import com.rightsidetech.http.base.BaseController;
import com.rightsidetech.user.dtos.response.LoginInfoResp;
import com.rightsidetech.user.service.UserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shenyu.client.springmvc.annotation.ShenyuSpringMvcClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Package: com.rightsidetech.http.controller.userApp.login
 * @ClassName: UserInfoController
 * @Author: yinj
 * @CreateTime: 2021/11/02 10:26
 * @Description:
 */
@Api(tags = "登录信息相关api")
@RestController
@RequestMapping("/userApp/user")
@ShenyuSpringMvcClient(path = "/userApp/user/**")
@Slf4j
public class LoginInfoController extends BaseController {

    @Resource
    private UserInfoService userInfoService;

    @Log
    @Token
    @GetMapping("/getLoginInfo")
    @ApiOperation("登录获取用户信息")
    public ResponseData<LoginInfoResp> getLoginInfo(){
        String userInfoId = getAttribute();
        LoginInfoResp resp = userInfoService.getLoginInfo(Long.parseLong(userInfoId));
        return ResponseData.success(resp);

    }


    @Log
    @Token
    @GetMapping("/logout")
    @ApiOperation("退出登录")
    public ResponseData logout(){
        String userInfoId = getAttribute();
        return userInfoService.logout(Long.parseLong(userInfoId));

    }




}
